home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9855 < prev    next >
Encoding:
Text File  |  1996-08-05  |  20.3 KB  |  835 lines

  1. Path: news.ac.net!pacifier!usenet
  2. From: David Lindsay <david.lindsay@columbian.com>
  3. Newsgroups: comp.lang.c
  4. Subject: True EOF problems
  5. Date: Wed, 13 Mar 1996 15:29:24 -0800
  6. Organization: The Columbian Newspaper
  7. Message-ID: <31475A54.24C0@columbian.com>
  8. NNTP-Posting-Host: 206.163.4.63
  9. Mime-Version: 1.0
  10. Content-Type: multipart/mixed; boundary="------------580764A32029"
  11. X-Mailer: Mozilla 2.0 (Win16; U)
  12.  
  13. This is a multi-part message in MIME format.
  14.  
  15. --------------580764A32029
  16. Content-Type: text/plain; charset=us-ascii
  17. Content-Transfer-Encoding: 7bit
  18.  
  19. Any assistance on this problem would be appreciated.
  20.  
  21. --------------580764A32029
  22. Content-Type: text/plain; charset=us-ascii
  23. Content-Transfer-Encoding: 7bit
  24. Content-Disposition: inline; filename="CQUEST2.TXT"
  25.  
  26. DISCLAIMER:
  27. I am a semi-novice at C having been programming in the language for about a year now.  I am self-taught through the K&R second edition and the Osborne "C The Complete Reference." I try to adhere to ANSI C.
  28.  
  29. Specs: INFILE - is an ASCII text file that has no Carriage Return/Line Feed
  30.  
  31. HISTORY:
  32. I have written a program that reads through INFILE. It does a gets() on INFILE to get a 1024 character record. I parse the string out into a set of character arrays. If EOF has *NOT* been reached then I read in another 1024 character record and parse that into another set of char arrays. I compare the AdNumbers from each of the records, if they do not match I process the first record and then do an fseek from the TOF to record_count -1 ( which should put it to the second gets() record's position in the file). If the AdNumbers match then I process both records and then do an fseek to the next record position. 
  33. Now to the meat of the problem:
  34. I have problems when I read in the last record, it doesn't always pick up the EOF - be it on the first gets() or the second.  I have had to write a work around that does a last gets() and if it doesn't have any data besides the EOF I'm finished.  Problem is, it doesn't  always seem to work.  Sometimes if it is processing the last two records in the file, the second record doesn't hit the EOF so my program assumes it's not EOF and reads in the last record again.
  35. QUESTION:
  36. Is there a better way to ensure *true* EOF while reading in two records at once and keeping track of how many records are processed.
  37. I have included my main() function for clarity of what I am trying to accomplish. I apologies for the length, but I prefer to give more information than less. 
  38. /* BILLCNV.C
  39.     This program converts the Cybergraphics Billing file to PBS
  40.     file layout specifications.
  41. Create Date:  05-JUN-95
  42. Programmer: David Lindsay
  43. */
  44.  
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #include <time.h>
  49. #include "billcnv.h"
  50. #include "lookup.h"
  51. #include "general.h"
  52.  
  53.  
  54. #define MAX 1025
  55.  
  56. FILE *infile = NULL;
  57. FILE *Tranfile;
  58. FILE *Classfile;
  59. FILE *Logfile;
  60. FILE *Errorfile;
  61.  
  62. void conv_hb_units(char inmult[], char inunits[]);
  63. void make_filename(char pmonth[], char pday[], char pyear[]);
  64. void loadcyber(char cybarray[], int num);
  65. void loadnext(char cybarray[], int num);
  66. void Title(void);
  67. void loadtable(void);
  68. void CreateOrder(void);
  69. void CreateCust(void);
  70. void CreatePubl(void);
  71. void CreateSched(char Indate[], char inPub[], char inZone[]);
  72. void CreateAddChrg(char OpArray[], char OpAmt[]);
  73. void Create_nOrder(void); /* Not Used */
  74. void Create_nCust(void); /* Not Used */
  75. void Create_nPubl(void);
  76. void Create_nSched(void);
  77. void Create_nAddChrg(char OpArray[], char OpAmt[]);
  78. void Schedule_it(void);
  79. void Schedule_it_CS(void);
  80. void Pipe(char pipearray[]);
  81. void find_ad_type(void);
  82. void is_flat_rate(void);
  83. void calc_grand_total(void);
  84. void calc_grand_total_MP(void);
  85. void load1strec(void);
  86. void load2ndrec(void);
  87. void makelogfile(void);
  88.  
  89. char Order[250];
  90. char Customer[375];
  91. char Publication[250];
  92. char Schedule[250];
  93. char AddCharge[250];
  94. char Log[250];
  95. char KickOut[250];
  96. char Outlog[256];
  97. char Classout[256];
  98. char Tranout[256];
  99. char Errorout[256] = "/pbs/exchange/Error";
  100. char UserExpDate[7];
  101. char str[1025];
  102. char nextrec[1025];
  103. char PreviousAd[15] = "0";
  104. char AdTotalStr[15];
  105. char TMTotalStr[15];
  106. char GrandTotalS[15];
  107. char MGPrice[3];
  108. char SchedDate[7];
  109. int codelook = 0; /* For debug purposes or "do nothing" statement.*/
  110. int reclen_cnt = 0;
  111. int n_reclen_cnt = 0;
  112. int record_cnt = 0;
  113. float AdValue = 0;
  114. int AdTotal = 0;
  115. int TMTotal = 0;
  116. int AdGrandTotal = 0;
  117. int TMGrandTotal = 0;
  118. int GrandTotal = 0;
  119. long seekval = 0;
  120. int isnc = 0;
  121. int ismpb = 0;
  122. int ismakegood = 0;
  123. int isnational = 0;
  124. int isflatrate = 0;
  125. int isflatrateCS = 0;
  126. int islegal = 0;
  127. int TFncnt = 0;
  128. int TFicnt = 0;
  129. int ThrownOut = 0;
  130. int IsOk = 0;
  131. int X1,X2,X3,X4,X5,X6,nX1,nX2,nX3,nX4,nX5,nX6 = 0;
  132. char answer[2];
  133. char tmcanswer[2];
  134. char hbanswer[2];
  135.  
  136. /* Start of main program */
  137.  
  138. void main(argc,argv)
  139. int  argc;
  140. char **argv;
  141.  
  142. {
  143.     if (argc != 2)
  144.     {
  145.     system("clear"); /* Clear Screen */
  146.     Title();
  147.         fprintf(stderr,"\tSyntax:");
  148.         fprintf(stderr,"         %s input_file\n\n\n\n\n\n\n\n\n\n\n",argv[0]);
  149.         exit(1);
  150.     }
  151.  
  152.     if ((infile = fopen(argv[1],"r")) == NULL)
  153.     {
  154.     system("clear"); /* Clear Screen */
  155.  
  156.     Title();
  157.         fprintf(stderr,
  158.         "\n\tCannot open '%s' or file doesn't exist - Check current directory.\n",argv[1]);
  159.         printf("\n\n\n\n\n\n\n\n\n\n\n");
  160.         exit(1);
  161.     }
  162.  
  163.  
  164.  
  165.     /* Get Expiration Date */
  166.  
  167.     do
  168.     {
  169.         int monthnum = 0;
  170.         int daynum = 0;
  171.         int yearnum = 0;
  172.         int montherror = 0;
  173.         int dayerror = 0;
  174.         char pmonth[3];
  175.         char pday[3];
  176.         char pyear[3];
  177.         char monthname[10];
  178.         char weekday[10];
  179.  
  180.         system("clear"); /* Clear Screen */
  181.  
  182.         Title();
  183.         printf("Enter Date of Expire(MMDDYY): ");
  184.         gets(UserExpDate);
  185.         UserExpDate[6] = '\0';
  186.     
  187.         parsedate(UserExpDate,pmonth,pday,pyear);
  188.  
  189.         montherror = find_month(pmonth, monthname);
  190.  
  191.         monthnum = atoi(pmonth);
  192.         daynum = atoi(pday);
  193.         yearnum = atoi(pyear);
  194.  
  195.         if (atoi(pday) > 0 &&
  196.             atoi(pday) <= find_maxdays(monthnum,yearnum))
  197.                 dayerror = 0;
  198.         else
  199.                 dayerror = 1;
  200.  
  201.         if    (montherror == 1)
  202.             {
  203.             printf("\n\nInvalid Month: '%s'\n\n", pmonth);
  204.             printf("Do you wish to re-enter date? (y or n) ");
  205.             gets(answer);
  206.                 if (strcmp(answer, "y") == 0 ||
  207.                 strcmp(answer, "Y") == 0)
  208.                 IsOk = 0;
  209.                 else
  210.                 {
  211.                 system ("clear");
  212.                 exit(1);
  213.                 }
  214.             }
  215.         else 
  216.             if (dayerror == 1)
  217.             {
  218.             printf("\n\n'%s' is an invalid date for ", pday);
  219.             printf("the Month of '%s'\n\n", monthname);
  220.             printf("Do you wish to re-enter date? (y or n) ");
  221.             gets(answer);
  222.                 if (strcmp(answer, "y") == 0 ||
  223.                 strcmp(answer, "Y") == 0)
  224.                 IsOk = 0;
  225.                 else
  226.                 {
  227.                 system ("clear");
  228.                 exit(1);
  229.                 }
  230.             }
  231.         else
  232.             {
  233. /*            find_weekday(weekday, monthnum, daynum, yearnum);
  234.             DelZero(pday);
  235.             printf("\n\n\n");
  236.             printf("\t\t\tYou entered %s, ", weekday);*/
  237.             printf("\t\t\tYou entered  ");
  238.             printf("%s ", monthname);
  239.             if (yearnum >= 50)
  240.                 printf("%s, 19", pday);
  241.             else
  242.                 printf("%s, 20", pday);
  243.  
  244.             printf("%s\n\n", pyear);
  245.  
  246.             printf("Is this correct? (y or n): ");
  247.             gets(answer);
  248.             answer[1] = '\0';
  249.  
  250.             if (strcmp(answer, "y") == 0 ||
  251.             strcmp(answer, "Y") == 0)
  252.                 {
  253.                 IsOk = 1;
  254.                 make_filename(pmonth, pday, pyear);
  255.                 }
  256.             }
  257.         }while (IsOk == 0); 
  258.  
  259.  
  260.         if ((Classfile = fopen(Classout,"w")) == NULL)
  261.         {
  262.             fprintf(stderr,"Cannot open or create '%s'.\n",Classout);
  263.             exit(1);
  264.         }
  265.  
  266.         if ((Tranfile = fopen(Tranout,"w")) == NULL)
  267.         {
  268.             fprintf(stderr,"Cannot open or create '%s'.\n",Tranout);
  269.             exit(1);
  270.         }
  271.  
  272.         if ((Errorfile = fopen(Errorout,"w")) == NULL)
  273.         {
  274.             fprintf(stderr,"Cannot open or create '%s'.\n",Errorout);
  275.             exit(1);
  276.         }
  277.  
  278.         if ((Logfile = fopen(Outlog,"w")) == NULL)
  279.         {
  280.             fprintf(stderr,"Cannot open or create '%s'.\n",Outlog);
  281.             exit(1);
  282.         }
  283.         else
  284.             {
  285.             /* Set up time stamp for Log file. */
  286.  
  287.             time_t timer;
  288.             struct tm *tblock;
  289.             char timestamp[20];
  290.  
  291.             /* get TOD */
  292.             timer = time(NULL);
  293.             /* converts dat/time to a structure */
  294.             tblock = localtime(&timer);
  295.             /* Put date and time in array */
  296.             strftime(timestamp, 20, "%c", tblock);
  297.  
  298.             strcpy(KickOut, "\t\t\tCybergraphics Conversion Log\n\n");
  299.             strcat(KickOut, timestamp);
  300.             strcat(KickOut, "\n\n");
  301.             strcat(KickOut, "ACCOUNT     NAME                            ");
  302.             strcat(KickOut, "TOTAL COST  AD #    PUB    STA\n");
  303.             strcat(KickOut, "---------   ------------------------------  ");
  304.             strcat(KickOut, "----------  ------  ---    ---\n");
  305.             fputs(KickOut, Logfile);
  306.             }
  307.  
  308.  
  309.     system("clear"); /* Clear Screen */
  310.  
  311.     /* Load Lookup Table */
  312.     loadtable();
  313.  
  314.     /* Initialize Make Good Price */
  315.     itoa (0, MGPrice );
  316.  
  317.  
  318.     /* Load the Cybergraphics Array */
  319.  
  320.     do
  321.     {
  322.  
  323.     fgets(str, MAX,infile);
  324.  
  325.     strcpy(nextrec,"");
  326.     strcat(nextrec,"\0");
  327.     strcpy(nAdNumber,"");
  328.     strcat(nAdNumber,"\0");
  329.  
  330.     load1strec();
  331.  
  332.     if (strcmp(AdNumber, "104517") == 0)
  333.         codelook = 1;
  334.  
  335.     if (!feof(infile))
  336.         {
  337.         fgets(nextrec, MAX,infile);
  338.         load2ndrec();
  339.         if (strcmp(nextrec, "") == 0)    
  340.             {
  341.             strcpy(nAdNumber,"");
  342.             strcat(nAdNumber,"\0");
  343.             }
  344.         }    
  345.  
  346.     record_cnt += 2;
  347.     if (strcmp(AdStatus,"I") == 0)
  348.         TFicnt += 1;
  349.  
  350.     if (strcmp(AdStatus,"N") == 0)
  351.         TFncnt += 1;
  352.  
  353.     reclen_cnt = 0;
  354.     n_reclen_cnt = 0;
  355.  
  356.     
  357.     if ((strcmp(TotalCost, "0000000000") == 0) &&
  358.         (strcmp(AdStatus, "I") == 0 ||
  359.          strcmp(AdStatus, "N") == 0) &&
  360.         (feof(infile)))/* EOF but not a TF*/
  361.         {
  362.         strcpy(KickOut, Account);
  363.         strcat(KickOut, "  ");
  364.         strcat(KickOut, Name);
  365.         strcat(KickOut, "  ");
  366.         strcat(KickOut, TotalCost);
  367.         strcat(KickOut, "  ");
  368.         strcat(KickOut, AdNumber);
  369.         strcat(KickOut, "\t");
  370.         strcat(KickOut, ClassCode);
  371.         strcat(KickOut, "\t");
  372.         strcat(KickOut, AdStatus);
  373.         strcat(KickOut, "\n");
  374.         fputs(KickOut, Logfile);
  375.         ThrownOut += 1;
  376.         }
  377.  
  378.     else
  379.     if ((strcmp(TotalCost, "0000000000") != 0) &&
  380.         (strcmp(AdStatus, "I") == 0 ||
  381.          strcmp(AdStatus, "N") == 0) &&
  382.         (feof(infile)))/* EOF but no a TF*/
  383.         {
  384.         strcpy(KickOut, Account);
  385.         strcat(KickOut, "  ");
  386.         strcat(KickOut, Name);
  387.         strcat(KickOut, "  ");
  388.         strcat(KickOut, TotalCost);
  389.         strcat(KickOut, "  ");
  390.         strcat(KickOut, AdNumber);
  391.         strcat(KickOut, "\t");
  392.         strcat(KickOut, ClassCode);
  393.         strcat(KickOut, "\t");
  394.         strcat(KickOut, AdStatus);
  395.         strcat(KickOut, "\n");
  396.         fputs(KickOut, Logfile);
  397.         
  398.  
  399.         /* Check to see if it is a Legal for later on. */
  400.         islegal = 0;
  401.  
  402.             if ((strcmp(ClassCode,"001") == 0) ||
  403.                 (strcmp(ClassCode,"002") == 0) ||
  404.                 (strcmp(ClassCode,"003") == 0) ||
  405.                 (strcmp(ClassCode,"004") == 0))
  406.                     islegal = 1;
  407.     
  408.         /* Check to see if it is a Flat Rate for later on. */
  409.     
  410.         isflatrate = 0;
  411.         isflatrateCS = 0;
  412.  
  413.         is_flat_rate();    
  414.  
  415.         ismpb = 0;
  416.  
  417.         if (strcmp(AdNumber,nAdNumber) != 0) /* AdNumbers don't match - not CS */
  418.             {
  419.     
  420.                 calc_grand_total();
  421.  
  422.             /* Load record in PBS record layout format for COL Publication*/
  423.  
  424.             CreateOrder();
  425.             CreateCust();
  426.             CreatePubl();
  427.             Schedule_it();
  428.     
  429.             /* Check for Additional Charges */
  430.     
  431.             if (isflatrate &&
  432.                 (strcmp(OptionsAmt1, "0000000000") == 0) && 
  433.                 (!strchr("L", *Options1) == 0)) 
  434.                     codelook = 1; /* Don't create Charge Record */
  435.             else
  436.                 if (!strchr(" ", *Options1))
  437.                     CreateAddChrg(Options1,OptionsAmt1);
  438.                     
  439.             if (isflatrate &&
  440.                 (strcmp(OptionsAmt2, "0000000000") == 0) && 
  441.                 (!strchr("L", *Options2) == 0)) 
  442.                     codelook = 1; /* Don't create Charge Record */
  443.             else
  444.                 if (!strchr(" ", *Options2))
  445.                     CreateAddChrg(Options2,OptionsAmt2);
  446.         
  447.             if (isflatrate &&
  448.                 (strcmp(OptionsAmt3, "0000000000") == 0) && 
  449.                 (!strchr("L", *Options3) == 0)) 
  450.                     codelook = 1; /* Don't create Charge Record */
  451.             else
  452.                 if (!strchr(" ", *Options3))
  453.                     CreateAddChrg(Options3,OptionsAmt3);
  454.         
  455.             if (isflatrate &&
  456.                 (strcmp(OptionsAmt4, "0000000000") == 0) && 
  457.                 (!strchr("L", *Options4) == 0)) 
  458.                     codelook = 1; /* Don't create Charge Record */
  459.             else
  460.                 if (!strchr(" ", *Options4))
  461.                     CreateAddChrg(Options4,OptionsAmt4);
  462.         
  463.             if (isflatrate &&
  464.                 (strcmp(OptionsAmt5, "0000000000") == 0) && 
  465.                 (!strchr("L", *Options5) == 0)) 
  466.                     codelook = 1; /* Don't create Charge Record */
  467.             else
  468.                 if (!strchr(" ", *Options5))
  469.                     CreateAddChrg(Options5,OptionsAmt5);
  470.         
  471.             if (isflatrate &&
  472.                 (strcmp(OptionsAmt6, "0000000000") == 0) && 
  473.                 (!strchr("L", *Options6) == 0)) 
  474.                     codelook = 1; /* Don't create Charge Record */
  475.             else
  476.                 if (!strchr(" ", *Options6))
  477.                     CreateAddChrg(Options6,OptionsAmt6);
  478.             
  479.             }
  480.  
  481.         else 
  482.     
  483.             {
  484.             /* Load record in PBS record layout format for Multi-Publications */
  485.     
  486.                 calc_grand_total_MP();
  487.     
  488.             ismpb = 1;
  489.  
  490.             CreateOrder();
  491.             CreateCust();
  492.             CreatePubl();
  493.             Schedule_it();
  494.             Create_nPubl();
  495.             Schedule_it_CS();
  496.     
  497.                 /* Check for Additional Charges */
  498.     
  499.                 if (!strchr(" ", *Options1))
  500.                     CreateAddChrg(Options1,OptionsAmt1);
  501.                 
  502.                 if (!strchr(" ", *Options2))
  503.                     CreateAddChrg(Options2,OptionsAmt2);
  504.     
  505.                 if (!strchr(" ", *Options3))
  506.                     CreateAddChrg(Options3,OptionsAmt3);
  507.     
  508.                 if (!strchr(" ", *Options4))
  509.                     CreateAddChrg(Options4,OptionsAmt4);
  510.     
  511.                 if (!strchr(" ", *Options5))
  512.                     CreateAddChrg(Options5,OptionsAmt5);
  513.     
  514.                 if (!strchr(" ", *Options6))
  515.                     CreateAddChrg(Options6,OptionsAmt6);
  516.     
  517.     
  518.                 /* Check for Additional Charges for nextrec */
  519.         
  520.                 if (!strchr(" ", *nOptions1))
  521.                     Create_nAddChrg(nOptions1,nOptionsAmt1);
  522.                 
  523.                 if (!strchr(" ", *nOptions2))
  524.                     Create_nAddChrg(nOptions2,nOptionsAmt2);
  525.     
  526.                 if (!strchr(" ", *nOptions3))
  527.                     Create_nAddChrg(nOptions3,nOptionsAmt3);
  528.     
  529.                 if (!strchr(" ", *nOptions4))
  530.                     Create_nAddChrg(nOptions4,nOptionsAmt4);
  531.     
  532.                 if (!strchr(" ", *nOptions5))
  533.                     Create_nAddChrg(nOptions5,nOptionsAmt5);
  534.     
  535.                 if (!strchr(" ", *nOptions6))
  536.                     Create_nAddChrg(nOptions6,nOptionsAmt6);
  537.             }    
  538.         }
  539.     
  540.     else
  541.     if (strcmp(AdNumber,nAdNumber) != 0 &&
  542.         (strcmp(TotalCost, "0000000000") == 0) &&
  543.         (strcmp(AdStatus, "I") == 0 ||
  544.          strcmp(AdStatus, "N") == 0))/* AdNumbers don't match and its a Non-billed TF */
  545.         {
  546.         strcpy(KickOut, Account);
  547.         strcat(KickOut, "  ");
  548.         strcat(KickOut, Name);
  549.         strcat(KickOut, "  ");
  550.         strcat(KickOut, TotalCost);
  551.         strcat(KickOut, "  ");
  552.         strcat(KickOut, AdNumber);
  553.         strcat(KickOut, "\t");
  554.         strcat(KickOut, ClassCode);
  555.         strcat(KickOut, "\t");
  556.         strcat(KickOut, AdStatus);
  557.         strcat(KickOut, "\n");
  558.         fputs(KickOut, Logfile);
  559.  
  560.         record_cnt--;
  561.         seekval = (record_cnt * (sizeof(str)-1));
  562.         fseek(infile, seekval, SEEK_SET);
  563.         ThrownOut += 1;
  564.         }
  565.  
  566.     else
  567.     if (strcmp(AdNumber,nAdNumber) == 0 &&
  568.         (strcmp(TotalCost, "0000000000") == 0) &&
  569.         (strcmp(AdStatus, "I") == 0 ||
  570.          strcmp(AdStatus, "N") == 0))/* AdNumbers match and its a Non-billed TF */
  571.         {
  572.         seekval = ((record_cnt + 1) * (sizeof(str)-1));
  573.         fseek(infile, seekval, SEEK_SET);
  574.         ThrownOut += 2;
  575.         }
  576.  
  577.     else
  578.         {
  579.         /* Check to see if it is a Legal for later on. */
  580.         islegal = 0;
  581.  
  582.             if ((strcmp(ClassCode,"001") == 0) ||
  583.                 (strcmp(ClassCode,"002") == 0) ||
  584.                 (strcmp(ClassCode,"003") == 0) ||
  585.                 (strcmp(ClassCode,"004") == 0))
  586.                     islegal = 1;
  587.     
  588.         /* Check to see if it is a Flat Rate for later on. */
  589.     
  590.         isflatrate = 0;
  591.         isflatrateCS = 0;
  592.  
  593.         is_flat_rate();    
  594.  
  595.         ismpb = 0;
  596.  
  597.         if (strcmp(AdNumber,nAdNumber) != 0 && (feof(infile))) /* AdNumbers don't match but eof */
  598.             {
  599.  
  600.                 calc_grand_total();
  601.  
  602.             /* Load record in PBS record layout format for COL Publication*/
  603.  
  604.             CreateOrder();
  605.             CreateCust();
  606.             CreatePubl();
  607.             Schedule_it();
  608.  
  609.             /* Check for Additional Charges */
  610.  
  611.             if (isflatrate &&
  612.                 (strcmp(OptionsAmt1, "0000000000") == 0) && 
  613.                 (!strchr("L", *Options1) == 0)) 
  614.                     codelook = 1; /* Don't create Charge Record */
  615.             else
  616.                 if (!strchr(" ", *Options1))
  617.                     CreateAddChrg(Options1,OptionsAmt1);
  618.                     
  619.             if (isflatrate &&
  620.                 (strcmp(OptionsAmt2, "0000000000") == 0) && 
  621.                 (!strchr("L", *Options2) == 0)) 
  622.                     codelook = 1; /* Don't create Charge Record */
  623.             else
  624.                 if (!strchr(" ", *Options2))
  625.                     CreateAddChrg(Options2,OptionsAmt2);
  626.         
  627.             if (isflatrate &&
  628.                 (strcmp(OptionsAmt3, "0000000000") == 0) && 
  629.                 (!strchr("L", *Options3) == 0)) 
  630.                     codelook = 1; /* Don't create Charge Record */
  631.             else
  632.                 if (!strchr(" ", *Options3))
  633.                     CreateAddChrg(Options3,OptionsAmt3);
  634.         
  635.             if (isflatrate &&
  636.                 (strcmp(OptionsAmt4, "0000000000") == 0) && 
  637.                 (!strchr("L", *Options4) == 0)) 
  638.                     codelook = 1; /* Don't create Charge Record */
  639.             else
  640.                 if (!strchr(" ", *Options4))
  641.                     CreateAddChrg(Options4,OptionsAmt4);
  642.         
  643.             if (isflatrate &&
  644.                 (strcmp(OptionsAmt5, "0000000000") == 0) && 
  645.                 (!strchr("L", *Options5) == 0)) 
  646.                     codelook = 1; /* Don't create Charge Record */
  647.             else
  648.                 if (!strchr(" ", *Options5))
  649.                     CreateAddChrg(Options5,OptionsAmt5);
  650.         
  651.             if (isflatrate &&
  652.                 (strcmp(OptionsAmt6, "0000000000") == 0) && 
  653.                 (!strchr("L", *Options6) == 0)) 
  654.                     codelook = 1; /* Don't create Charge Record */
  655.             else
  656.                 if (!strchr(" ", *Options6))
  657.                     CreateAddChrg(Options6,OptionsAmt6);
  658.             
  659.             }
  660.     
  661.         else 
  662.         if (strcmp(AdNumber,nAdNumber) != 0) /* AdNumbers don't match - not CS */
  663.             {
  664.     
  665.                 calc_grand_total();
  666.  
  667.             /* Load record in PBS record layout format for COL Publication*/
  668.  
  669.             CreateOrder();
  670.             CreateCust();
  671.             CreatePubl();
  672.             Schedule_it();
  673.     
  674.             /* Check for Additional Charges */
  675.     
  676.             if (isflatrate &&
  677.                 (strcmp(OptionsAmt1, "0000000000") == 0) && 
  678.                 (!strchr("L", *Options1) == 0)) 
  679.                     codelook = 1; /* Don't create Charge Record */
  680.             else
  681.                 if (!strchr(" ", *Options1))
  682.                     CreateAddChrg(Options1,OptionsAmt1);
  683.                     
  684.             if (isflatrate &&
  685.                 (strcmp(OptionsAmt2, "0000000000") == 0) && 
  686.                 (!strchr("L", *Options2) == 0)) 
  687.                     codelook = 1; /* Don't create Charge Record */
  688.             else
  689.                 if (!strchr(" ", *Options2))
  690.                     CreateAddChrg(Options2,OptionsAmt2);
  691.         
  692.             if (isflatrate &&
  693.                 (strcmp(OptionsAmt3, "0000000000") == 0) && 
  694.                 (!strchr("L", *Options3) == 0)) 
  695.                     codelook = 1; /* Don't create Charge Record */
  696.             else
  697.                 if (!strchr(" ", *Options3))
  698.                     CreateAddChrg(Options3,OptionsAmt3);
  699.         
  700.             if (isflatrate &&
  701.                 (strcmp(OptionsAmt4, "0000000000") == 0) && 
  702.                 (!strchr("L", *Options4) == 0)) 
  703.                     codelook = 1; /* Don't create Charge Record */
  704.             else
  705.                 if (!strchr(" ", *Options4))
  706.                     CreateAddChrg(Options4,OptionsAmt4);
  707.         
  708.             if (isflatrate &&
  709.                 (strcmp(OptionsAmt5, "0000000000") == 0) && 
  710.                 (!strchr("L", *Options5) == 0)) 
  711.                     codelook = 1; /* Don't create Charge Record */
  712.             else
  713.                 if (!strchr(" ", *Options5))
  714.                     CreateAddChrg(Options5,OptionsAmt5);
  715.         
  716.             if (isflatrate &&
  717.                 (strcmp(OptionsAmt6, "0000000000") == 0) && 
  718.                 (!strchr("L", *Options6) == 0)) 
  719.                     codelook = 1; /* Don't create Charge Record */
  720.             else
  721.                 if (!strchr(" ", *Options6))
  722.                     CreateAddChrg(Options6,OptionsAmt6);
  723.             
  724.             record_cnt--;
  725.             seekval = (record_cnt * (sizeof(str)-1));
  726.             fseek(infile, seekval, SEEK_SET);
  727.     
  728.             }
  729.  
  730.         else 
  731.     
  732.             {
  733.             /* Load record in PBS record layout format for Multi-Publications */
  734.     
  735.                 calc_grand_total_MP();
  736.     
  737.             ismpb = 1;
  738.  
  739.             CreateOrder();
  740.             CreateCust();
  741.             CreatePubl();
  742.             Schedule_it();
  743.             Create_nPubl();
  744.             Schedule_it_CS();
  745.     
  746.                 /* Check for Additional Charges */
  747.     
  748.                 if (!strchr(" ", *Options1))
  749.                     CreateAddChrg(Options1,OptionsAmt1);
  750.                 
  751.                 if (!strchr(" ", *Options2))
  752.                     CreateAddChrg(Options2,OptionsAmt2);
  753.     
  754.                 if (!strchr(" ", *Options3))
  755.                     CreateAddChrg(Options3,OptionsAmt3);
  756.     
  757.                 if (!strchr(" ", *Options4))
  758.                     CreateAddChrg(Options4,OptionsAmt4);
  759.     
  760.                 if (!strchr(" ", *Options5))
  761.                     CreateAddChrg(Options5,OptionsAmt5);
  762.     
  763.                 if (!strchr(" ", *Options6))
  764.                     CreateAddChrg(Options6,OptionsAmt6);
  765.     
  766.     
  767.                 /* Check for Additional Charges for nextrec */
  768.         
  769.                 if (!strchr(" ", *nOptions1))
  770.                     Create_nAddChrg(nOptions1,nOptionsAmt1);
  771.                 
  772.                 if (!strchr(" ", *nOptions2))
  773.                     Create_nAddChrg(nOptions2,nOptionsAmt2);
  774.     
  775.                 if (!strchr(" ", *nOptions3))
  776.                     Create_nAddChrg(nOptions3,nOptionsAmt3);
  777.     
  778.                 if (!strchr(" ", *nOptions4))
  779.                     Create_nAddChrg(nOptions4,nOptionsAmt4);
  780.     
  781.                 if (!strchr(" ", *nOptions5))
  782.                     Create_nAddChrg(nOptions5,nOptionsAmt5);
  783.     
  784.                 if (!strchr(" ", *nOptions6))
  785.                     Create_nAddChrg(nOptions6,nOptionsAmt6);
  786.             }
  787.         }
  788.     }while(!feof(infile));
  789.         
  790. fclose(infile);
  791. fclose(Classfile);
  792. fclose(Tranfile);
  793.  
  794.         Title();
  795.         fprintf(stderr,"\n\tInput file name     : %s\n",argv[1]);
  796.         fprintf(stderr,"\tOutput file name    : %s\n",Classout);
  797. printf("\n\n\n\n\n\t\t\tRecords Converted: %d \n\n",record_cnt - 1);
  798. printf("\n\n\n\n\n");
  799.  
  800. makelogfile();
  801. fclose(Logfile);
  802. fclose(Errorfile);
  803.  
  804. /* Append Errors to Log File */
  805.         if ((Errorfile = fopen(Errorout,"r")) == NULL)
  806.         {
  807.             fprintf(stderr,"Cannot open '%s'.\n",Errorout);
  808.             exit(1);
  809.         }
  810.  
  811.         if ((Logfile = fopen(Outlog,"a")) == NULL)
  812.         {
  813.             fprintf(stderr,"Cannot open or create '%s'.\n",Outlog);
  814.             exit(1);
  815.         }
  816.  
  817.         {
  818.         char ch;
  819.         while((ch=fgetc(Errorfile))!=EOF)
  820.             {
  821.             fputc(ch, Logfile);
  822.             }
  823.  
  824.         }
  825. fclose(Logfile);
  826. fclose(Errorfile);
  827.  
  828. } /* End of Main Program */
  829.  
  830. /* Procedures for Program -  see also date.c, createrec.c, general.c */
  831.  
  832.  
  833. --------------580764A32029--
  834.  
  835.